package com.itheima.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.entity.common.UploadResult;
import com.itheima.service.PicUploadService;
import com.itheima.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("file")
public class PicUploadController {

    @Autowired
    private PicUploadService picUploadService;

    @PostMapping("upload")
    public JSONObject upload(@RequestParam("file") MultipartFile file){
        UploadResult upload = picUploadService.upload(file, "goods");
        return ResultUtils.successData(upload, "success");
    }
}
